<template>
	<div class="steps-container">
		<el-card shadow="hover" header="数据结果">
			<el-row>
				<el-date-picker
					v-model="date"
					type="datetimerange"
					range-separator="To"
					start-placeholder="Start date"
					end-placeholder="End date"
				/>
			</el-row>
			<el-row>
				<el-select v-model="select_type" class="m-2" placeholder="Select" size="large">
				<el-option
					v-for="item in options"
					:key="item.value"
					:label="item.label"
					:value="item.value"
				/>
				</el-select>
			</el-row>
			<el-row>
				<el-button @click="onNextSteps" size="default" class="mt15" type="primary">
				<SvgIcon name="iconfont icon-step" />
				读取
			</el-button>
			<el-button @click="clear" size="default" class="mt15" type="danger">
				<SvgIcon name="iconfont icon-step" />
				清除
			</el-button>
			<el-button @click="exportExcel" size="default" class="mt15" type="danger">
				<SvgIcon name="iconfont icon-step" />
				导出
			</el-button>
			</el-row>
			<el-table :data="tableData" style="width: 100%">
				<el-table-column prop="province" label="省"/>
				<el-table-column prop="city" label="市"/>
				<el-table-column prop="tcNumber" label="统筹编号"/>
				<el-table-column prop="orgcode" label="定点编号" />
				<el-table-column prop="name" label="机构名称" />
				<el-table-column prop="livePerMonth" label="月活"/>
				<el-table-column prop="type" label="产品类型"/>
				<el-table-column prop="cloud" label="云" />
				<el-table-column prop="cloudType" label="云类别" />
			</el-table>
		</el-card>
	</div>
</template>

<script lang="ts">
import { toRefs, reactive, defineComponent } from 'vue';
import post from '/@/utils/post';
import json from '/@/common/json';
import excel from '/@/common/excel';
import area from '/@/config/area';
import common from '/@/common/common';

export default defineComponent({
	name: 'customUpdate',
	setup() {
		const state = reactive({
			tableData: [],
			date: null,
			select_type: '',
			options: [
				{value: '海南电信云医院',label: '海南电信云医院',},
				{value: '海南电信云药店正式',label: '海南电信云药店正式',},
				{value: '广西移动云医院',label: '广西移动云医院',},
				{value: '广西移动云药店',label: '广西移动云药店',},
			]
		});
		// 下一步点击
		const clear = () => {
			state.tableData = []
		}
		const exportExcel = () => {
			excel.exportExcel(state.tableData, "文件")
		}
		const hainan_dianxin_his = () => {
			let start_time: string
			let end_time: string
			if (common.objectAvailable(state.date)) {
				start_time = common.gmtToString(state.date[0],common.YYYYMMDD)
				end_time = common.gmtToString(state.date[1],common.YYYYMMDD)
			} else {
				alert('请选择时间')
				return
			}
			//查询海南电信医院数据
			post.postList({},'http://localhost:8600/api/neuyyfftool/comHospitalinfo/query').then(res=>{
				let result = res.data
				//只要海南医院
				result = json.delRowbyCol(result, 'orgcodeYb', 'H460', json.NOT_LIKE)
				for (let item of result) {
					//查询月活
					//住院
					post.postList({orgcode: item.orgcodeYb},"http://localhost:8600/api/neuyyfftool/siIpsSetlinfo/query/1/1/CRTE_TIME >=to_date('"+start_time+"','yyyymmdd hh24:mi:ss') and CRTE_TIME <to_date('"+end_time+"','yyyymmdd hh24:mi:ss')").then(res=>{
						let ips = res.data['total']
						post.postList({orgcode: item.orgcodeYb},"http://localhost:8600/api/neuyyfftool/siOpbSetlinfo/query/1/1/CRTE_TIME >=to_date('"+start_time+"','yyyymmdd hh24:mi:ss') and CRTE_TIME <to_date('"+end_time+"','yyyymmdd hh24:mi:ss')").then(res=>{
							state.tableData.push(
								{
									province: area.getSingleInfo(item.orgcodeYb, area.PROVINCE_NAME),
									city: area.getSingleInfo(item.orgcodeYb, area.CITY_NAME),
									tcNumber: item.orgcodeYb.substring(1,7),
									orgcode: item.orgcodeYb,
									name: item.orgname,
									livePerMonth: ips + res.data['total'],
									type: 'HSAF云医院',
									cloud: '是',
									cloudType: '海南电信云'
								}
							)
						})
					})
				}
			})
		}
		const onNextSteps = () => {
			if (common.objectAvailable(state.select_type)) {
				switch (state.select_type) {
					case '海南电信云医院':
						hainan_dianxin_his()
						break
				}
			} else {
				alert('请选择数据类型')
			}
		}
		return {
			onNextSteps,
			clear,
			exportExcel,
			...toRefs(state),
		};
	}
})
</script>
